package cn.myschool.java79.test;

import cn.myschool.java79.dao.SubjectMapper;
import cn.myschool.java79.entity.Subject;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Arrays;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class FirstMyBAtis {
    public static void main(String[] args) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sqlSessionFactory.openSession();

        //>Connection connection = session.getConnection();
        //1:
//        List<Subject> s = session.selectList("cn.myschool.java79.dao.StudentDao.findALL");
//        s.forEach(System.out::println);
        //2:
        SubjectMapper mapper = session.getMapper(SubjectMapper.class);
        System.out.println(mapper.getClass().getName());
        System.out.println("父类:"+mapper.getClass().getSuperclass());
        System.out.println("接口:");
        System.out.println(Arrays.toString(mapper.getClass().getInterfaces()));
        List<Subject> data = mapper.findALL();
        data.forEach(System.out::println);
        session.close();
    }
}
